package ch.hearc.ig.android.crudpersonnes.screen;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import ch.hearc.ig.android.crudpersonnes.business.Personne;
import ch.hearc.ig.android.crudpersonnes.screen.tool.PersonneAdapter;

/**
 * A fragment representing a single Personne detail screen. This fragment is
 * either contained in a {@link PersonneListActivity} in two-pane mode (on
 * tablets) or a {@link PersonneDetailActivity} on handsets.
 */
public class PersonneDetailFragment extends Fragment {
	/**
	 * The fragment argument representing the item ID that this fragment
	 * represents.
	 */
	public static final String ARG_ITEM_ID = "item_id";

	/**
	 * The dummy content this fragment is presenting.

	private DummyContent.DummyItem mItem;
		 */
	private Personne mPersonne;
	
	/**
	 * Mandatory empty constructor for the fragment manager to instantiate the
	 * fragment (e.g. upon screen orientation changes).
	 */
	public PersonneDetailFragment() {
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setHasOptionsMenu(true);
		

		if (getArguments().containsKey(ARG_ITEM_ID)) {
			// Load the dummy content specified by the fragment
			// arguments. In a real-world scenario, use a Loader
			// to load content from a content provider.
			mPersonne = PersonneAdapter.personne_map.get(getArguments().getString(
					ARG_ITEM_ID));
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_personne_detail,
				container, false);

		/*
		 * Here we have maybe to change the output to have an nice class
		 * 
		 */
		if (mPersonne != null) {
			((TextView) rootView.findViewById(R.id.textFirstname)).setText(mPersonne.getPrenom());
            ((TextView) rootView.findViewById(R.id.textLastname)).setText(mPersonne.getNom());
            ((TextView) rootView.findViewById(R.id.textAddress)).setText(mPersonne.getAdresse());
            ((TextView) rootView.findViewById(R.id.textCity)).setText(mPersonne.getVille());
		}

		return rootView;
	}
	

	@Override
    public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
        inflater.inflate(R.menu.main, menu);
        super.onCreateOptionsMenu(menu, inflater);
    }
}

